home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / agblankers / source / cubes / blank.c next >
C/C++ Source or Header  |  1995-02-27  |  6KB  |  214 lines

  1. /* --------------------------------------------------------
  2.  *   Recursively draws cubes.
  3.  *   
  4.  *                                           010294 kha.
  5.  * -------------------------------------------------------- */
  6.  
  7. #include <exec/memory.h>
  8. #include <math.h>
  9.  
  10. #include "/includes.h"
  11.  
  12.  
  13. #define WINCO(SIZE,MAX) ((int) (( (int)((SIZE+2.0)*MAX) ) / 4 ) )
  14. #define bool int
  15. #ifndef TRUE
  16. #define TRUE 1
  17. #define FALSE 0
  18. #endif
  19.  
  20. static LONG male(int factor, int p, int xlimit, int ylimit, int wx1, int wy1, int wx2, int wy2, struct RastPort *rp);
  21. static  __inline void malequadrat(int x1,int y1, int x2, int y2, struct RastPort *rp);
  22.  
  23.  
  24. Triplet *ColorTable = 0L;
  25.  
  26. int COLORS;
  27. int OFFSET;
  28. int DEPTH;
  29. int RANDOMBORDER;
  30. int MAXBORDER;
  31.  
  32. VOID Defaults( PrefObject *Prefs )
  33. {
  34.     Prefs[0].po_ModeID = getTopScreenMode();
  35.     Prefs[0].po_Depth = 4;
  36. }
  37.  
  38. LONG Cubes( struct Screen *scr, SHORT width, SHORT height )
  39. {
  40.   LONG flg_end = OK;
  41.   struct RastPort *rp = &( scr->RastPort );
  42.   int wx,wy,wxsize,wysize;
  43.     int factor;
  44.     int minxsize;
  45.     int minysize;
  46.     int p;
  47.     int i;
  48.     
  49.   wxsize = width-1; wysize = height-1;
  50.   SetRast( rp, 0 );
  51.   ScreenToFront( scr );
  52.  
  53.     while (1)
  54.       { /* bestimme naechste Quadrate */
  55.         switch(RangeRand(8))
  56.           { case 0: case 1: case 2: case 3:
  57.               { /* the default configuration */
  58.                 factor = RangeRand(3) + 2;  /* [x/factor] vs. [factor-x/factor] */
  59.                 minxsize = RangeRand(20)+3; /* end computation if x-size < minxsize */
  60.                 minysize = RangeRand(12)+2; /* or if y-size < minysize (plus borders) */
  61.                 p = RangeRand(10) + 5;      /* probability of "random computation abort"
  62.                                        * = 1/p */
  63.                 break;
  64.               }
  65.             case 4: case 5: case 6:
  66.               { /* BIG rectangles */
  67.                 factor = RangeRand(4) + 2;
  68.                 minxsize = RangeRand(30)+3;
  69.                 minysize = RangeRand(15)+2;
  70.                 p = RangeRand(5) + 5;
  71.                 break;
  72.               }
  73.             case 7: 
  74.               { /* tiny rectangles */
  75.                 factor = RangeRand(4) + 2;
  76.                 minxsize = RangeRand(5) + 2;
  77.                 minysize = RangeRand(3) + 1;
  78.                 p = RangeRand(20) + 10;
  79.                 break;
  80.               }
  81.             default:
  82.               { /* OOOPS */
  83.                 factor = 3;
  84.                 minxsize = 100;
  85.                 minysize = 100;
  86.                 p = 2;
  87.                 break;
  88.               }
  89.           }
  90.  
  91.         OFFSET = 0;
  92.         COLORS = (1 << scr->BitMap.Depth);
  93.         /* Color options */
  94.     if (COLORS > 8 && RangeRand(4))
  95.            { if (RangeRand(2))
  96.            { /* select the first 8 colors */
  97.                  OFFSET = RangeRand(COLORS-8);
  98.                  COLORS = 8;
  99.                }
  100.              else
  101.                { OFFSET = RangeRand(COLORS*3/4);
  102.                  COLORS = COLORS / 4;
  103.                }
  104.            }
  105.  
  106.         RANDOMBORDER = RangeRand(2);
  107.         MAXBORDER = 3;
  108.         if (!RANDOMBORDER) { MAXBORDER = RangeRand(4); }
  109.  
  110.         DEPTH=0;
  111.         if ((flg_end = male(factor,p,minxsize,minysize,0,0,wxsize,wysize,rp)) != OK)
  112.            { return flg_end;
  113.            }
  114.         for (i=0; i<10; i++)
  115.           { Delay(25); /* mehr als eine halbe Sekunde merkt man */
  116.             ScreenToFront(scr);
  117.         flg_end = ContinueBlanking();
  118.         if (flg_end != OK) return flg_end;
  119.           }
  120.       }
  121.   }
  122.  
  123.  
  124.  
  125. static LONG male(int factor, int p, int xlimit, int ylimit, int wx1, int wy1, int wx2, int wy2, struct RastPort *rp)
  126.   { LONG result = ContinueBlanking();
  127.     if (result != OK) return result;
  128.  
  129.     if (wx2-wx1 < xlimit+2*MAXBORDER || wy2 - wy1 < ylimit+2*MAXBORDER || !(RangeRand(p)||DEPTH==0))
  130.        { malequadrat(wx1,wy1,wx2,wy2,rp);
  131.          return OK;
  132.        }
  133.     else
  134.        { int xmid, ymid, q;
  135.          DEPTH++; 
  136.          if (DEPTH>200)
  137.            { malequadrat(wx1,wy1,wx2,wy2,rp);
  138.              return OK;
  139.            }
  140.          q = RangeRand(factor)+1; xmid = (wx1 * q + wx2 * (factor - q)) / factor;
  141.          q = RangeRand(factor)+1; ymid = (wy1 * q + wy2 * (factor - q)) / factor;
  142.          if ((result = male(factor,p,xlimit,ylimit,wx1,wy1,xmid-1,ymid-1,rp)) != OK)
  143.             { return result;
  144.             }
  145.          if ((result = male(factor,p,xlimit,ylimit,xmid,ymid,wx2,wy2,rp)) != OK)
  146.             { return result;
  147.             }
  148.          if ((result = male(factor,p,xlimit,ylimit,xmid,wy1,wx2,ymid-1,rp)) != OK)
  149.             { return result;
  150.             }
  151.          result = male(factor,p,xlimit,ylimit,wx1,ymid,xmid-1,wy2,rp);
  152.      DEPTH--;
  153.          return result;
  154.        }
  155.   }
  156.  
  157. static __inline void malequadrat(int x1,int y1, int x2, int y2, struct RastPort *rp)
  158.   { int border;
  159.     int color;
  160.     
  161.     if (RANDOMBORDER)
  162.        { border = RangeRand(MAXBORDER);
  163.        }
  164.     else
  165.        { border = MAXBORDER;
  166.        }
  167.     if ((x2-x1)>border*2 && (y2-y1)>border*2) {
  168.     if (border)
  169.        { SetAPen(rp,0);
  170.          RectFill(rp,x1,y1,x2,y2);
  171.          x1 = x1 + border; y1 = y1 + border;
  172.          x2 = x2 - border; y2 = y2 - border;
  173.        }
  174.     color = RangeRand(COLORS-1)+1 + OFFSET; /* nicht farbe 0 */
  175.     SetAPen(rp,color);
  176.     RectFill(rp,x1,y1,x2,y2);
  177.    }
  178.  else if (x2>x1 && y2>y1)
  179.        { SetAPen(rp,0);
  180.          RectFill(rp,x1,y1,x2,y2);
  181.        }
  182.   }
  183.  
  184.  
  185. /* Adopted from the Dragon blanker */
  186. LONG Blank( PrefObject *Prefs )
  187. {
  188.     struct Screen *Scr;
  189.     struct Window *Wnd;
  190.     LONG RetVal;
  191.     
  192.     if( Scr = OpenScreenTags( NULL, SA_Depth, Prefs[0].po_Depth,
  193.                              SA_Quiet, TRUE, SA_DisplayID, Prefs[0].po_ModeID,
  194.                              SA_Behind, TRUE, SA_Overscan, OSCAN_STANDARD,
  195.                              TAG_DONE ))
  196.     {
  197.         SetRGB4(&( Scr->ViewPort ), 0, 0, 0, 0 );
  198.         ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  199.         Wnd = BlankMousePointer( Scr );
  200.         
  201.         do
  202.             RetVal = Cubes( Scr, Scr->Width, Scr->Height );
  203.         while( RetVal == OK );
  204.         
  205.         UnblankMousePointer( Wnd );
  206.         RainbowPalette( 0L, ColorTable, 1L, 0L );
  207.         CloseScreen( Scr );
  208.     }
  209.     else
  210.         RetVal = FAILED;
  211.     
  212.     return RetVal;
  213. }
  214.